<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="文件名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入文件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="fileInfoLogList" @selection-change="handleSelectionChange">
      <el-table-column label="文件类型" align="center" prop="name" >
        <template slot-scope="scope">
          <svg-icon :icon-class="getIcon(scope.row.type)" style="font-size: 32px"/>
        </template>
      </el-table-column>
      <el-table-column label="文件名称" align="center" prop="name" />
      <el-table-column label="文件后缀" align="center" prop="type" />
      <el-table-column label="文件大小" align="center" prop="size" />
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改文件日志对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <el-row>

<el-col :span="12">
</el-col>
<el-col :span="12">
        <el-form-item label="父部门id" prop="parentId">
          <el-input v-model="form.parentId" placeholder="请输入父部门id" />
        </el-form-item>
</el-col>
<el-col :span="12">
</el-col>
<el-col :span="12">
        <el-form-item label="文件名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入文件名称" />
        </el-form-item>
</el-col>
<el-col :span="12">
</el-col>
<el-col :span="12">
</el-col>
<el-col :span="12">
</el-col>
<el-col :span="12">
</el-col>
<el-col :span="12">
</el-col>
<el-col :span="12">
        <el-form-item label="文件地址" prop="url">
          <el-input v-model="form.url" placeholder="请输入文件地址" />
        </el-form-item>
</el-col>
<el-col :span="12">
        <el-form-item label="文件大小" prop="size">
          <el-input v-model="form.size" placeholder="请输入文件大小" />
        </el-form-item>
</el-col>
<el-col :span="12">
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
</el-col>
<el-col :span="12">
        <el-form-item label="排序" prop="seqNo">
          <el-input v-model="form.seqNo" placeholder="请输入排序" />
        </el-form-item>
</el-col>


          </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFileInfoLog, getFileInfoLog, delFileInfoLog, addFileInfoLog, updateFileInfoLog } from "@/api/fileInfo/fileInfoLog";

export default {
  name: "FileInfoLog",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 文件日志表格数据
      fileInfoLogList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        parentId: null,
        ancestors: null,
        name: null,
        type: null,
        url: null,
        size: null,
        seqNo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询文件日志列表 */
    getList() {
      this.loading = true;
      listFileInfoLog(this.queryParams).then(response => {
        this.fileInfoLogList = response.data;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        parentId: null,
        ancestors: null,
        name: null,
        type: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        url: null,
        size: null,
        remark: null,
        seqNo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加文件日志";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids[0]
      getFileInfoLog(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改文件日志";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFileInfoLog(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFileInfoLog(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除选择的数据项？').then(function() {
        return delFileInfoLog(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('fileInfo/fileInfoLog/export', {
        ...this.queryParams
      }, `fileInfoLog_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
